<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="layui/css/modules/layer/default/layer.css">
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/form.css">
</head>

<body>
    <form action="" class="layui-form loginForm" >

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名" autocomplete="on" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">

            <div class="layui-input-block">
                <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <button class="layui-btn" style="width:74%;position: absolute;left:86px;" lay-submit lay-filter="login"  >登陆</button>
            <a id="toReg" href="register.html" style="position: relative; top:65px;clear:both;left:100px;">还没有账号？点我注册</a>

        </div>
    </form>

    <script src="js/jquery.min.js"></script>
    <script src="layui/layui.js"></script>
    <script src="layui/lay/modules/layer.js"></script>
    <script src="js/index.js"></script>

    <script>
        layui.use('form', function(){
            var form = layui.form;

            //监听提交
            form.on('submit(login)', function(data){
                $.ajax({
                   url:'http://localhost:8080/api/login'
                   ,type:'post'
                   ,contentType:"application/json"
                   ,data:JSON.stringify(data.field)
                   ,success:function(result){
                       layer.msg(result.msg);
                       if(result.code!=200){
                           return;
                       }else{
                           layer.msg(result.msg,{
                               time:500
                           });
						   var storage=window.localStorage;
						   storage.setItem("uid",result.data.uid)
						   //console.log(storage.uid);
                           self.location='index.html';
						   
                       }

                    }

                });
                return false;
            });
        });
    </script>
</body>
<style>

</style>

</html>